package com.aivin.service.impl;

import com.aivin.dao.IPicDao;
import com.aivin.entity.*;
import com.aivin.service.PicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * Created by Administrator on 2016/8/22.
 */
@Service
public class PicServiceImpl  implements PicService{

    @Autowired
    private IPicDao ipdao ;

   public  List<TbPic> getAllPicFy( int offset  , int limit ){

        return  ipdao.queryAllPicFy(offset,limit);
    }


    public  List<TbPic> getAllPicByUserId(int  userId ,int offset  , int limit ){

        return  ipdao.queryAllPicFyByUserId( userId ,offset,limit);
    }

    public   PicAndUserGroupBean  getResultBydKeyWorldFy( String  keyWord , int offset  , int  limit){
        PicAndUserGroupBean bean = new PicAndUserGroupBean();

        List<TbPic>  picList = null ;
        List<TbUser> userList = null;
        int picSize = getPicRecodeSize(keyWord);
        int userSize  =getUserRecodeSize(keyWord);
        picList = ipdao.getPicResultBydKeyWorldFy(keyWord, offset, limit);
        userList = ipdao.getUserResultBydKeyWorldFy(keyWord, offset, limit);
        bean.setPicList(picList);
        bean.setPicSize(picSize);
        bean.setUserList(userList);
        bean.setUserSize(userSize);
        return bean ;
    }

    public int getPicRecodeSize(String  keyWord){
        int size= 0 ;
        size= ipdao.getPicRecodeSize(keyWord);
        return  size;
    }

    public int getUserRecodeSize(String  keyWord){
        int size= 0 ;
        size= ipdao.getUserRecodeSize(keyWord);
        return  size;
    }

    public int getAllPicSizeByUserId(int userId){
        int picSize = 0 ;
        picSize= ipdao.getAllPicSizeByUserId(userId);
        return picSize ;
    }

    public int getPiclikeCountByPicId (@PathVariable int picId    ){
        int  size    = ipdao.getPiclikeCountByPicId(picId) ;
        return size ;

    }

    public int getiiclikedStateByPicIdAndUserId (@PathVariable int picId  ,@PathVariable int userId    ){

        int  size    = ipdao.getiiclikedStateByPicIdAndUserId(picId ,userId) ;
        return size ;
    }

    public int getPicLikedStateByUser(@PathVariable int picId   ,@PathVariable int userId  ){
        PiclikedtableBean bean  = ipdao.getPicLikedStateByUser(picId, userId) ;
        int state =   bean==null ?  -1  : bean.getLikestate() ;
        return state ;
    }

    public int setPicLikedStateByUser(@PathVariable int likestate ,@PathVariable int picId   ,@PathVariable int userId  ){
       int state  = ipdao.setPicLikedStateByUser(likestate,picId, userId) ;

        return state ;
    }


    public int  publishPic (@PathVariable  TbPic picBean  ){
        int state  = ipdao.publishPic(picBean) ;
        return picBean.getPicId()  ;//  state
    }


    public int   addPicLikedStateByUserId(@PathVariable PiclikedBean bean){
        int state  = ipdao.addPicLikedStateByUserId(bean) ;
        return  state  ;//
    }
    /**get some picInfo recoomend by system**/
    public List<RecommendInfoBean> getRecommendPics(  ){
        return  ipdao.getRecommendPics();
    }

    /**用户点赞列表、用户图片收藏列表**/
    public List<PiclikedtableBean> queryPicLikedListByUserId( int userId  , int offset , int limit){
      return  ipdao.queryPicLikedListByUserId(userId ,offset ,limit) ;
    }

    /**根据图片id获取图片信息**/
    public TbPic queryPicInfoByPicId(int picId){
        return ipdao.queryPicInfoByPicId(picId) ;
    }
}
